package com.atguigu.multiReading;

import java.util.Arrays;
import java.util.Stack;

class ListNode{
    int val;
    ListNode next;
    ListNode(int x){
        val=x;
    }
}
public class demo16 {
    public static void main(String[] args) {
        ListNode head=new ListNode(1);
        head.next=new ListNode(3);
        head.next.next=new ListNode(2);
        System.out.println(Arrays.toString(Solution2.reversePrint(head)));
    }
}
class Solution2{
    public static int[] reversePrint(ListNode head){
        Stack<Integer> stack=new Stack<>();
        while(head.next!=null){
            stack.push(head.val);
            head=head.next;
        }
        int[] res=new int[stack.size()];
        for(int i=0;i<res.length;i++){
            res[i]=stack.pop();
        }
        return res;
    }
}
